﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wicresoft.SMS.Data;

namespace Wicresoft.SMS.Gateway.Host
{
    class DBLog
    {
        private static LogService log;
        private static IServiceConfigProvider  iscp;
        private static string pruductname = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() + " " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
        private static string currentuser = "HOST";

        private static void WriteLog(string type, string msg)
        {
            try
            {
                if (log == null)
                {
                    IConnectStringProvider icsp = new AppConfigProvider();
                    iscp = new AppConfigProvider();
                    log = new LogService(icsp.ConnectionString);
                }
                log.WriteLog(DateTime.Now, pruductname, type, msg, currentuser);
            }
            catch (Exception)
            {

            }

        }


        public static void Exception(string msg)
        {
            WriteLog("Exception", msg);
        }

        public static void Exception(string msg, Exception ex)
        {
            WriteLog("Exception", msg + " ex:" + ex.ToString());
        }

        public static void Debug(string msg)
        {
            if (iscp.AllowDebugLog)
                WriteLog("Debug", msg);
        }

        public static void Info(string msg)
        {
            WriteLog("Info", msg);
        }

        public static void Error(string msg)
        {
            WriteLog("Error", msg);
        }
    }
}
